/*
 *
 *  Copyright (C) 2009 GSyC/LibreSoft
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Author : Roberto Calvo Palomino <rocapal@gsyc.es>
 *
 */

package com.LibreGeoSocial.App.Routes;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;

import com.LibreGeoSocial.App.R;

public class RoutePreferences extends PreferenceActivity 
//implements OnSharedPreferenceChangeListener 
{

	public static String KEY_LOCATION_PROVIDERS  = "ROUTE_location_providers";
	public static String KEY_LOCATION_UNITS 	 = "ROUTE_location_unit";
	public static String KEY_LOCATION_PERIODIC   = "ROUTE_location_periodic";
	public static String KEY_LOCATION_MANUAL     = "ROUTE_location_manual";
	public static String KEY_LOCATION_DISTANCE	 = "ROUTE_location_distance";
	
	public static String KEY_LOCATION_WRITERMODE = "ROUTE_location_writermode";
	public static String KEY_LOCATION_SERVICE    = "ROUTE_location_service";
	
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setPreferenceScreen(createPreferenceHierarchy());
        
        // Set up a listener whenever a key changes            
        //getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    }

    private PreferenceScreen createPreferenceHierarchy() {
        // Root
        PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);

        // Location method preferences
        PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
        dialogBasedPrefCat.setTitle("Location (service)");
        root.addPreference(dialogBasedPrefCat);
        
        // Manual Location
        CheckBoxPreference servicePref = new CheckBoxPreference(this);
        servicePref.setKey(KEY_LOCATION_SERVICE);
        servicePref.setTitle("Active Location Service");
        servicePref.setSummary("The service runs ever if the app is closed");
        dialogBasedPrefCat.addPreference(servicePref);
        
        // List location methods
        ListPreference listPref = new ListPreference(this);
        listPref.setEntries(R.array.location_methods);
        listPref.setEntryValues(R.array.valueslocation_methods);
        listPref.setDialogTitle("Location Providers");
        listPref.setKey(KEY_LOCATION_PROVIDERS);
        listPref.setTitle("Location provider");
        listPref.setSummary("Choose the provider for your location");
        dialogBasedPrefCat.addPreference(listPref);
        
        //List location time units
        ListPreference listPrefUnits = new ListPreference(this);
        listPrefUnits.setEntries(R.array.location_units);
        listPrefUnits.setEntryValues(R.array.valueslocation_units);
        listPrefUnits.setDialogTitle("Location Units");
        listPrefUnits.setKey(KEY_LOCATION_UNITS);
        listPrefUnits.setTitle("Time units");
        listPrefUnits.setSummary("Choose the time unit");
        dialogBasedPrefCat.addPreference(listPrefUnits);
        
        // List location time periodic
        ListPreference listPrefPeriodic = new ListPreference(this);
        listPrefPeriodic.setEntries(R.array.location_periodic);
        listPrefPeriodic.setEntryValues(R.array.location_periodic);
        listPrefPeriodic.setDialogTitle("Location Periodic");
        listPrefPeriodic.setKey(KEY_LOCATION_PERIODIC);
        listPrefPeriodic.setTitle("Time periodic");
        listPrefPeriodic.setSummary("Choose the time periodic");
        dialogBasedPrefCat.addPreference(listPrefPeriodic);
        
        // List minimum distance
        ListPreference listPrefDistance = new ListPreference(this);
        listPrefDistance.setEntries(R.array.values_minimumdistance);
        listPrefDistance.setEntryValues(R.array.values_minimumdistance);
        listPrefDistance.setDialogTitle("Minimum Distance");
        listPrefDistance.setKey(KEY_LOCATION_DISTANCE);
        listPrefDistance.setTitle("Minimum Distance");
        listPrefDistance.setSummary("Choose the minimum distance gps refresh");
        dialogBasedPrefCat.addPreference(listPrefDistance);
        
        /*
        PreferenceCategory dialogBasedPrefStor = new PreferenceCategory(this);
        dialogBasedPrefStor.setTitle("Routes");
        root.addPreference(dialogBasedPrefStor);
        
        // Manual Location
        CheckBoxPreference manualPrefStor = new CheckBoxPreference(this);
        manualPrefStor.setKey(KEY_LOCATION_WRITERMODE);
        manualPrefStor.setTitle("Active SD-card Storage");
        manualPrefStor.setSummary("This option active the routes storage in sdcard");
        dialogBasedPrefStor.addPreference(manualPrefStor);
        
        
        // Manual Location
        CheckBoxPreference manualPref = new CheckBoxPreference(this);
        manualPref.setKey(KEY_LOCATION_MANUAL);
        manualPref.setTitle("Active Manual Location");
        manualPref.setSummary("This option active the manual location for routes");
        dialogBasedPrefStor.addPreference(manualPref);
        */

        return root;
    }

    /*
	public void onSharedPreferenceChanged (SharedPreferences sharedPreferences, String key) {
    
		if (key.equals(KEY_LOCATION_PROVIDERS)) {
			String location = sharedPreferences.getString(key, "");
			
			if (location.equals("gps"))
				RouteMap.LocationProvider = LocationManager.GPS_PROVIDER;
			
			else if (location=="wifi")			
				RouteMap.LocationProvider = LocationManager.NETWORK_PROVIDER;
			
			
		} else if (key.equals(KEY_LOCATION_UNITS)) {
			
			String s_unit = sharedPreferences.getString(key, "");
			
			Integer unit = Integer.valueOf(s_unit);
			
			if (unit == 1)
				RouteMap.LocationUnit = 1;
			else if (unit == 60)
			   	RouteMap.LocationUnit = 60;

		} else if (key.equals(KEY_LOCATION_PERIODIC)) {
			
			String s_periodic = sharedPreferences.getString(key, "");
			
			Integer periodic = Integer.valueOf(s_periodic);
			RouteMap.LocationPeriodic = periodic;
			
		} else if (key.equals(KEY_LOCATION_MANUAL)) {
		
			Boolean manualLoc = sharedPreferences.getBoolean(key, true);
			
			RouteMap.ActiveManualLocation = manualLoc;
			
		}
		
		
		

    }
    */

}
